import 'package:flutter/material.dart';
import 'package:gw_github_flutter/common/route_name.dart';
import 'package:gw_github_flutter/models/repo.dart';
import 'package:gw_github_flutter/tools/gwGetManager.dart';

class SliverRoute extends StatefulWidget {
  SliverRoute({Key? key}) : super(key: key);

  @override
  State<SliverRoute> createState() => _SliverRouteState();
}

class _SliverRouteState extends State<SliverRoute> {
  static const loadingTag = "##loading##"; //表尾标记
  var _items = [
    Repo()
      ..name = RouteName.sliverRoute_appBar + " 带tabbar 带刷新"
      ..route_path = RouteName.sliverRoute_appBar,
    Repo()
      ..name = RouteName.sliverRoute_noAppBar + " 带刷新"
      ..route_path = RouteName.sliverRoute_noAppBar,
    Repo()
      ..name = RouteName.sliverRoute_stickyHeader + " 粘性header 非sectionHeader"
      ..route_path = RouteName.sliverRoute_stickyHeader,
    Repo()
      ..name = RouteName.sliverRoute_tableView + " 带sectionHeader 带刷新"
      ..route_path = RouteName.sliverRoute_tableView,
    Repo()
      ..name = RouteName.sliverRoute_tableView_appBar + " 带sectionHeader 带刷新 带轮播"
      ..route_path = RouteName.sliverRoute_tableView_appBar,
    Repo()
      ..name = RouteName.sliverRoute_tableView_customSection + " 带sectionHeader"
      ..route_path = RouteName.sliverRoute_tableView_customSection,
    Repo()
      ..name = RouteName.sliverRoute_tableView_tabbar + " pageView 带刷新"
      ..route_path = RouteName.sliverRoute_tableView_tabbar,
    Repo()
      ..name = RouteName.sliverRoute_sideHeader + "带刷新"
      ..route_path = RouteName.sliverRoute_sideHeader,
    Repo()
      ..name = RouteName.sliverRoute_AZList + "A-Z排序"
      ..route_path = RouteName.sliverRoute_AZList,
    Repo()..name = loadingTag
  ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(RouteName.sliverRoute),
      ),
      body: Container(
        child: ListView.separated(
          itemCount: _items.length,
          separatorBuilder: (context, index) => Divider(
            color: Colors.yellow,
            height: .0,
          ),
          itemBuilder: (context, index) {
            if (_items[index].name == loadingTag) {
              return Container(
                padding: const EdgeInsets.all(16.0),
                alignment: Alignment.center,
                child: Text(
                  "没有更多了",
                  style: TextStyle(color: Colors.grey,fontSize: 13),
                ),
              );
            }
            return ListTile(
              title: Text(_items[index].name),
              subtitle: Text(_items[index].route_path ?? ""),
              onTap: () {
                GwGetRouteManager.pushName(_items[index].route_path ?? "");
              },
            );
          },
        ),
      ),
    );
  }
}
